---
title: 'Building Support for Green Investments'
author:
- Juliette Beaucousin, Jaroslaw Kantorowicz, Marian Moszoro

output:
  pdf_document: default
  html_document: default
---

```{r setup, include=FALSE, echo=FALSE, message=FALSE, warning=FALSE}
knitr::opts_chunk$set(echo=FALSE, message=FALSE, warning=FALSE, results = "hide")
```

# Loading packages

```{r}

# Load the packages

library(tidyverse)
library(cregg)
library(ggsci)
library(ggtext)
```

# Loading data and transformations

```{r fig.show="hide"}

# Load the data
climate_policies <- readRDS("green_investments.RDS")

# Check the names of the variables
names(climate_policies)

# Perform transformations

# Rename the variables
climate_policies_trans <- climate_policies %>% dplyr::rename(Effect.of.investment="Effect.van.de.investeringen") %>% 
  dplyr::rename(Financing.of.investment="Financiering.van.investeringen") %>% 
  dplyr::rename(Place.of.investment="Plaats.van.investering") %>% 
  dplyr::rename(Type.of.investment="Soort.investering") %>% 
  dplyr::select(Response.ID, 
                task, 
                respondent, 
                Effect.of.investment, 
                selected, 
                respondentIndex,
                Financing.of.investment,
                Place.of.investment,
                Type.of.investment)

# Attribute: Effects of investments

climate_policies_trans$Effect.of.investment <- factor(climate_policies_trans$Effect.of.investment)

climate_policies_trans$Effect.of.investment <- recode_factor(climate_policies_trans$Effect.of.investment, 
              "Creëert banen" = "Create jobs", 
              "Toename in economische groei" = "Increase economic growth",
              "Verbetert de biodiversiteit" = "Restore biodiversity",
              "Vermindert de CO2 uitstoot" = "Reduce CO2 emissions")

climate_policies_trans$Effect.of.investment <- factor(climate_policies_trans$Effect.of.investment, 
              levels = c("Restore biodiversity",
                         "Increase economic growth",
                         "Create jobs",
                         "Reduce CO2 emissions"))

# Attribute: Financing mode

climate_policies_trans$Financing.of.investment <- as.factor(climate_policies_trans$Financing.of.investment)

climate_policies_trans$Financing.of.investment <- recode_factor(climate_policies_trans$Financing.of.investment,
              "Verhoging van de brandstofbelasting in Nederland"  = "Fuel tax",
              "Verhoging van de BTW in Nederland" = "VAT",
              "Verhoging van de inkomstenbelasting in Nederland" = "Income tax",
              "Verhoging van de Nederlandse staatsschuld" = "Public debt")

climate_policies_trans$Financing.of.investment <- factor(climate_policies_trans$Financing.of.investment, 
              levels = c("VAT",
                         "Income tax",
                         "Fuel tax",
                         "Public debt"))

# Attribute: Place of investment

climate_policies_trans$Place.of.investment <- as.factor(climate_policies_trans$Place.of.investment)

climate_policies_trans$Place.of.investment <- recode_factor(climate_policies_trans$Place.of.investment,
              "Ethiopië"  = "Ethiopia", 
              "Nederland" = "The Netherlands",
              "Polen" = "Poland",
              "Suriname" = "Suriname")

climate_policies_trans$Place.of.investment <- factor(climate_policies_trans$Place.of.investment, 
              levels = c("The Netherlands", 
                         "Suriname", 
                         "Ethiopia", 
                         "Poland"))

climate_policies_trans$Location.of.investment <- as.factor(climate_policies_trans$Place.of.investment)

climate_policies_trans$Location.of.investment <- recode_factor(climate_policies_trans$Location.of.investment,
              "Ethiopia"  = "Abroad",
              "Nederland" = "The Netherlands",
              "Poland" = "Abroad",
              "Suriname" = "Abroad")

climate_policies_trans$Location.of.investment <- factor(climate_policies_trans$Location.of.investment, 
              levels = c("The Netherlands", 
                         "Abroad"))

# Attribute: Type of investment

climate_policies_trans$Type.of.investment <- as.factor(climate_policies_trans$Type.of.investment)

climate_policies_trans$Type.of.investment <- recode_factor(climate_policies_trans$Type.of.investment, 
              "Aanpassing van gebouwen"  = "Building retrofitting", 
              "Duurzaam openbaar vervoer" = "Sustainable public transportation",
              "Duurzame landbouw" = "Sustainable farming",
              "Schone elektrische stroom" = "Clean electricity")

climate_policies_trans$Type.of.investment <- factor(climate_policies_trans$Type.of.investment, 
              levels = c("Building retrofitting",
                         "Sustainable public transportation",
                         "Clean electricity",
                         "Sustainable farming"))

```

# Main result

```{r}

# Create the main figure: Figure

main_plot <- plot(amce(climate_policies_trans, selected ~ 
                         Type.of.investment +
                         Effect.of.investment + 
                         Location.of.investment +
                         Financing.of.investment, 
                       id = ~Response.ID,
                       feature_labels = c(Type.of.investment = "Type of investment", 
                                     Effect.of.investment="Effect of investment",
                                     Location.of.investment="Location of investment",
                                     Financing.of.investment = "Financing of investment")), 
                       size = 2,
                       header_fmt = "Attribute: %s") + 
              theme(legend.position = "none",
                    strip.text.y = element_text(face = "bold")) +
              scale_color_aaas() +
              annotate("segment", 
                       x = -2, 
                       xend = 2, 
                       y= 13.3, 
                       yend=13.3, 
                       color = "black", 
                       linetype = "dashed", 
                       linewidth = 0.3) +
              annotate("segment", 
                       x = -2, 
                       xend = 2, 
                       y= 18.3, 
                       yend=18.3, 
                       color = "black", 
                       linetype = "dashed", 
                       linewidth = 0.3) +
              annotate("segment", 
                       x = -2, 
                       xend = 2, 
                       y= 8.3, 
                       yend=8.3, 
                       color = "black", 
                       linetype = "dashed", 
                       linewidth = 0.3) +
              annotate("segment", 
                       x = -2, 
                       xend = 2, 
                       y= 5.3, 
                       yend=5.3, 
                       color = "black", 
                       linetype = "dashed", 
                       linewidth = 0.3)

# Save the figure

ggsave(main_plot, 
       file = "figure_1.jpg", 
       height = 7, 
       width = 7,
       scale = 0.7)

```

# Verifying the number of unique respondents

```{r}

# Examine the number of unique respondents

data_drop_na <- climate_policies_trans %>% drop_na(selected)

dra_drop_na_distinct <- data_drop_na %>% distinct(Response.ID)

##### END ##### END ##### END ##### END ##### END #####

```

